import React from "react";
import {Link} from "react-router";
import TableHeader from "../../components/table-header";
export default class News extends React.Component {

    constructor(...props) {
        super(...props);
        this.state = {
            list: []
        };
    }

    componentDidMount() {
        $.get('/admin/news/all', (list)=> {
            this.setState({list});
        });
    }

    render() {
        const data = this.state.list.map((item,index)=>{
           return  (
               <tr key={index}>
                   <td>{item.newsId}</td>
                   <td>{item.title}</td>
                   <td><Link to={'/news/'+item.newsId+'/post'}>编辑</Link></td>
               </tr>
           )
        });
        return (
            <div className="site-news news-index">
                <h2>文章管理</h2>
                <p>
                    <Link to="/news/post" className="btn btn-success">添加</Link>
                </p>
                <div className="table-responsive">
                    <table className="table table-bordered">
                        <TableHeader sections={['id','标题','操作']}/>
                        <tbody>{data}</tbody>
                    </table>
                </div>
            </div>
        )
    }
}